package com.hsy.linemoney.modules.common;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hsy.linemoney.R;

/**
 * Created by MartinKent on 2016/7/11.
 */
public class StepView extends RelativeLayout {
    private static final int step_done = R.mipmap.ic_step_done;
    private static final int step_undone = R.mipmap.ic_step_undone;
    private static final int step_doing_1 = R.mipmap.ic_step_doing_1;
    private static final int step_doing_2 = R.mipmap.ic_step_doing_2;
    private static final int step_doing_3 = R.mipmap.ic_step_doing_3;

    private static final int step_line_done = R.color.color_step_line_done;
    private static final int step_line_undone = R.color.color_step_line_undone;

    private static final int step_name_style_done = R.style.font_step_name_style_done;
    private static final int step_name_style_undone = R.style.font_step_name_style_undone;

    protected ImageView stepLine1;
    protected ImageView stepLine2;
    protected ImageView stepLine3;
    protected ImageView stepIcon1;
    protected TextView stepName1;
    protected ImageView stepIcon2;
    protected TextView stepName2;
    protected ImageView stepIcon3;
    protected TextView stepName3;
    protected ImageView stepIcon4;
    protected TextView stepName4;

    private View rootView;

    public StepView(Context context) {
        super(context);
        init(context);
    }

    public StepView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public StepView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        rootView = inflate(context, R.layout.inc_step_view, this);
        initView(rootView);
    }

    private void initView(View rootView) {
        stepLine1 = (ImageView) rootView.findViewById(R.id.step_line_1);
        stepLine2 = (ImageView) rootView.findViewById(R.id.step_line_2);
        stepLine3 = (ImageView) rootView.findViewById(R.id.step_line_3);
        stepIcon1 = (ImageView) rootView.findViewById(R.id.step_icon_1);
        stepName1 = (TextView) rootView.findViewById(R.id.step_name_1);
        stepIcon2 = (ImageView) rootView.findViewById(R.id.step_icon_2);
        stepName2 = (TextView) rootView.findViewById(R.id.step_name_2);
        stepIcon3 = (ImageView) rootView.findViewById(R.id.step_icon_3);
        stepName3 = (TextView) rootView.findViewById(R.id.step_name_3);
        stepIcon4 = (ImageView) rootView.findViewById(R.id.step_icon_4);
        stepName4 = (TextView) rootView.findViewById(R.id.step_name_4);
    }

    public void setCurrentStep(int step) {
        switch (step) {
            case 1:
                break;
            case 2:
                stepIcon1.setImageResource(step_done);
                stepIcon2.setImageResource(step_doing_2);
                stepIcon3.setImageResource(step_undone);
                stepIcon4.setImageResource(step_undone);
                stepLine1.setImageResource(step_line_done);
                stepLine2.setImageResource(step_line_undone);
                stepLine3.setImageResource(step_line_undone);
                stepName1.setTextAppearance(getContext(), step_name_style_done);
                stepName2.setTextAppearance(getContext(), step_name_style_done);
                stepName3.setTextAppearance(getContext(), step_name_style_undone);
                stepName4.setTextAppearance(getContext(), step_name_style_undone);
                break;
            case 3:
                stepIcon1.setImageResource(step_done);
                stepIcon2.setImageResource(step_done);
                stepIcon3.setImageResource(step_doing_3);
                stepIcon4.setImageResource(step_undone);
                stepLine1.setImageResource(step_line_done);
                stepLine2.setImageResource(step_line_done);
                stepLine3.setImageResource(step_line_undone);
                stepName1.setTextAppearance(getContext(), step_name_style_done);
                stepName2.setTextAppearance(getContext(), step_name_style_done);
                stepName3.setTextAppearance(getContext(), step_name_style_done);
                stepName4.setTextAppearance(getContext(), step_name_style_undone);
                break;
        }
    }
}
